package cn.dengta.webapp.user.vo;

import java.math.BigDecimal;
import java.util.Map;

import cn.dengta.common.model.Messager;
import cn.dengta.webapp.base.vo.AbstractVO;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.codeplayer.util.NumberUtil;

import static cn.dengta.common.model.APIResponse.Field;

@Getter
@Setter
@Accessors(chain = true)
public class UserOnlineVO extends AbstractVO<Void> {

	private String selectKey;
	@Field(name = "用户ID")
	private Long userId;
	@Field(name = "用户数据")
	private Map<String, Object> user;
	@Field(name = "总在线时长")
	private Long onlineTime;
	@Field(name = "用户数")
	private Long userCount;
	private BigDecimal totalIncome;
	private Integer greetCount;
	/** 昨日搭讪数 */
	private Integer yesterdayGreetCount;

	public long addOnlineTime(long time) {
		return (onlineTime == null ? 0L : onlineTime) + time;
	}
	public int addGreetCount(int time) {
		return (greetCount == null ? 0 : greetCount) + time;
	}

	public int addYesterdayGreetCount(int time) {
		return (yesterdayGreetCount == null ? 0 : yesterdayGreetCount) + time;
	}

	public static UserOnlineVO addOnlineTime(UserOnlineVO target, UserOnlineVO vo2) {
		if (target == null) {
			return vo2;
		} else if (vo2 != null) {
			target.setOnlineTime(target.addOnlineTime(NumberUtil.getLong(vo2.getOnlineTime(), 0L)));
			target.setGreetCount(target.addGreetCount(NumberUtil.getInt(vo2.getGreetCount(), 0)));
			target.setYesterdayGreetCount(target.addYesterdayGreetCount(NumberUtil.getInt(vo2.getYesterdayGreetCount(), 0)));
		}
		return target;
	}

}
